<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('角色列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>
								角色名称：<input type="text" name="roleName" placeholder="请输入角色名称"/>
							</li>
							<li>
								权限字符：<input type="text" name="roleKey" placeholder="请输入权限字符"/>
							</li>
							<li>
								角色状态：
								<select name="status" th:with="type=${@dict.getDict('sys_data_status')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictName}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li class="select-time">
								<label>创建时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="query[startTime]"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="query[endTime]"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-default btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
		
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-primary" onclick="$.operate.add()" shiro:hasPermission="system:role:add">
	                <i class="fa fa-plus"></i> 新增
	            </a>
	            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:role:edit">
		            <i class="fa fa-edit"></i> 修改
		        </a>
				<a class="btn btn-primary multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:role:remove">
		            <i class="fa fa-trash"></i> 删除
		        </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var prefix = ctx + "system/role";

		$(function() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        sortName: "createTime",
		        sortOrder: "desc",
		        modalName: "角色",
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'id',
		            visible: false
		        },
		        {
		            field: 'roleName',
		            title: '角色名称',
		            sortable: true
		        },
		        {
		            field: 'roleKey',
		            title: '权限字符',
		            sortable: true
		        },
		        {
		            field: 'orderNum',
		            title: '显示顺序',
		            sortable: true
		        },
		        {
		        	field: 'status',
		        	title: '角色状态',
		        	align: 'center'
		        },
		        {
		            field: 'createTime',
		            title: '创建时间',
		            sortable: true
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	return $('#operateTpl').tmpl(row).html();
		            }
		        }]
		    };
		    $.table.init(options);
		});
		
		/* 角色管理-授权数据权限 */
		function authDataScope(roleId) {
		    var url = prefix + '/authDataScope/' + roleId;
		    $.modal.open("授权数据权限", url);
		}
		
		/* 角色管理-授权菜单权限 */
		function authMenuScope(roleId) {
		    var url = prefix + '/authMenuScope/' + roleId;
		    $.modal.open("授权菜单权限", url);
		}
		
		/* 角色管理-分配用户 */
		function authUser(roleId) {
		    var url = prefix + '/authUser/' + roleId;
		    $.modal.openTab("分配用户", url);
		}
		
	</script>
</body>
<!-- 表格操作列 -->
<script id="operateTpl" type="text/template">
<tmpl>
	<a href="javascript:$.operate.edit('${id}')" shiro:hasPermission="system:role:edit" class="btn btn-primary btn-xs">
		<i class="fa fa-edit"></i> 修改
	</a>
	<a href="javascript:authMenuScope('${id}')" shiro:hasPermission="system:role:edit" class="btn btn-primary btn-xs">
		<i class="fa fa-bars"></i> 菜单权限
	</a>
	<a href="javascript:authDataScope('${id}')" shiro:hasPermission="system:user:edit" class="btn btn-primary btn-xs">
		<i class="fa fa-check-square-o"></i> 数据权限
	</a>
	<a href="javascript:authUser('${id}')" shiro:hasPermission="system:user:edit" class="btn btn-primary btn-xs">
		<i class="fa fa-user"></i> 分配用户
	</a>
	<a href="javascript:$.operate.remove('${id}')" shiro:hasPermission="system:role:remove" class="btn btn-danger btn-xs">
		<i class="fa fa-trash"></i> 删除
	</a> 
</tmpl>
</script>
</html>